package com.qhhc.hospital.controller;

import com.qhhc.hospital.entity.Drug;
import com.qhhc.hospital.service.IDrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DrugController {
    @Autowired
    IDrugService drugService;

    @RequestMapping("/insertDrug")
    public String insertDrug(@RequestBody Drug drug){
        drugService.insert(drug);
        return "success";
    }

    @RequestMapping("/getAllDrugs")
    public List<Drug> getAllDrugs(){
        List<Drug> drugs = drugService.selectAll();
        return drugs;
    }

    @RequestMapping("/getDrug/{drId}")
    public Drug getDrugById(@PathVariable("drId") Integer drId){
        return drugService.selectById(drId);
    }

    @RequestMapping("/updateDrug")
    public String updateDrug(@RequestBody Drug drug){
        drugService.update(drug);
        return "success";
    }

    @RequestMapping("/deleteDrug/{drId}")
    public String deleteDrug(@PathVariable("drId") Integer drId){
        drugService.delete(drId);
        return "success";
    }
} 